/*
 * 컴파일을 위해 올려 놓은 소스 입니다.
 * 서버에 반영하지 마시고 다른국가에 적용할 경우 서버에 있는 class 를 카피해서 사용하십시오.
 * 
 */

/*
 * Created on 2004. 9. 24.
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package com.pushmsg.OmaOtaConf.OmaOtaObject;

import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import java.util.*;
/**
 * @author dgchun
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class ProfileReader  extends DefaultHandler
{
	String filename = null;
	Hashtable ht = new Hashtable();
	String part = null;
	
	public ProfileReader(String filename)
	{
		this.filename = filename;
	}
	
	 
	  public Hashtable getProfile()
	  {
		SAXParserFactory   f = SAXParserFactory.newInstance();
		SAXParser          p = null;
		DefaultHandler     h = this;
		
		try
		{
		   	p = f.newSAXParser();
		   
			InputSource inputsource = new InputSource(filename);
		  	p.parse(inputsource, h);
		  	return ht;
		 } 
		catch(Throwable x)
		{
		  x.printStackTrace();
		  return null;
		}
	  }

	  public void startDocument()	throws SAXException
	  {
	  	//System.out.println("startDocument");
	  }

	  public void startElement(String ns, String sName, String qName, Attributes a)	throws SAXException
	  {
	  	String element = sName!=""?sName:qName;
	  	//System.out.println(element);
	  	if(element.equals("PARAM"))
	  	{
  			String key = a.getValue(0);
  			//System.out.println(key);
  			String value = a.getValue(1);
  			//System.out.println(value);
  			ht.put(key, value);			
	  	}
	  	else if(element.equals("CHARACTERISTIC"))
	  	{
	  		if(a.getValue(0).equals("URL")||a.getValue(0).equals("MMSURL"))
	  		{
	  			String key = "URL";
	  			String value = a.getValue(1);
	  			ht.put(key, value);
	  		}
	  	}	  	
	  }

	  public void characters(char[] buf, int offset, int length)	throws SAXException
	  {
	  }

	  public void endElement(String ns, String lName, String qName)	throws SAXException
	  {
	  		String element = lName!=""?lName:qName;
	  }

	  public void endDocument()	throws SAXException
	  {
	  	 //System.out.println("endDocument");
	  }

}
